/*
 * Copyright 2011 J. Auer, J. Andert, F.-J. Jendrusch, U. Celebi
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.fuberlin.replication.storage.jdbc.sqlite;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * SQLite iterator.
 * 
 * @param <T> the transfer object type
 */
public abstract class SQLiteIterator<T> {
	private ResultSet res;

	private ArrayList<T> list;
	private Iterator<T> iterator = null;

	/**
	 * Does the ResultSet have further rows?
	 */
	protected boolean hasNext;

	/**
	 * @param res ResultSet for the iterator
	 */
	public SQLiteIterator(ResultSet res) {
		this.res = res;
		this.list = new ArrayList<T>();
	}

	/**
	 * Returns the ResultSet to iterate over.
	 * 
	 * @return ResultSet to iterate over
	 */
	protected ResultSet getResultSet() {
		return res;
	}

	/**
	 * @return List for data objects
	 */
	protected ArrayList<T> getList() {
		return list;
	}

	/**
	 * @return the iterator
	 */
	public Iterator<T> getIterator() {
		return iterator;
	}

	/**
	 * @param iterator the iterator to set
	 */
	protected void setIterator(Iterator<T> iterator) {
		this.iterator = iterator;
	}

	/**
	 * The subclasses need to set the iterator.
	 */
	public abstract void setIterator();
}